<?php

class GL_Index extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->layout->setLayout("home/layout");
    }

    public function index()
    {
        $page = $this->input->get('page');
        $sort = $this->input->get('sort');
        $cat = $this->input->get('cat');
        $uid = $this->input->get('uid');
        $query = $this->input->get('q');
        $tag = $this->input->get('tag');
        if ($page==null) $page = 0;
        if ($sort==null) $sort = 1;
        if ($cat==null) $cat = 0;
        if ($uid==null) $uid = 0;
        if ($query==null) $query = '';
        if ($tag==null) $tag = 0;

        $data['products'] = $this->product->get_all_product($sort,$cat,$uid,$query,$tag);
        $data['page'] = $page;
        $data['sort'] = $sort;
        $data['cat'] = $cat;
        $data['uid'] = $uid;
        $data['query'] = $query;
        for ($i = $page*25; $i < count($data['products']) && $i < $page*25+25; $i++) {
            $data['images'][$i] = $this->product->get_images($data['products'][$i]->id);
        }
        $this->layout->view("home/index", $data);
    }

    public function makemoney()
    {
        $this->layout->view("home/makemoney");
    }

    public function contact()
    {
        $this->layout->view("home/contact");
    }

    public function upgrade()
    {
        $email = $this->session->userdata('logged_in')["id"];
        if($this->user->edit_permission($email,2))
        {
            echo 1;
            $sess = $this->session->userdata('logged_in');
            $sess['permission'] = 2;
            $this->session->set_userdata('logged_in', $sess);
        }
    }



}